//===============================================================================
// Microsoft patterns & practices
// Web Client Software Factory
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using System;
using System.Text;
using System.Collections.Generic;
using System.Web.Security;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WCSFContrib.ECommerceCatalog.Admin.Views;
using WCSFContrib.ECommerceCatalog.Admin.Tests.Mocks;
using WCSFContrib.ECommerceCatalog.BusinessEntities;
using WCSFContrib.ECommerceCatalog.BusinessEntities.Enums;

namespace WCSFContrib.ECommerceCatalog.Admin.Tests
{
    /// <summary>
    /// Summary description for DefaultViewPresenterTestFixture
    /// </summary>
    [TestClass]
    public class DefaultViewPresenterTestFixture
    {
        private MockDefaultView _view;
        private MockAdminController _controller;
        
        public DefaultViewPresenterTestFixture()
        {
        }

        private DefaultViewPresenter GetDefaultViewPresenterInitialized()
        {
            _controller = new MockAdminController();
            _view = new MockDefaultView();
            DefaultViewPresenter presenter = new DefaultViewPresenter(_controller);
            presenter.View = _view;

            return presenter;
        }

        [TestMethod]
        public void ShouldShowOrdersOnViewLoaded()
        {
            DefaultViewPresenter presenter = GetDefaultViewPresenterInitialized();

            presenter.OnViewLoaded();

            Assert.IsTrue(_controller.GetOrdersCalled);
            Assert.IsTrue(_view.ShowOrdersCalled);
            Assert.IsTrue(_view.ShowUsersCalled);
            Assert.AreEqual(2, _view.TotalOrdersCount);
            Assert.AreEqual(5, _view.TotalUsersCount);
        }

        [TestMethod]
        public void ShouldChangeOrderStatus()
        {
            DefaultViewPresenter presenter = GetDefaultViewPresenterInitialized();
            OrderStatus newOrderStatus = OrderStatus.ReadyToShip;
            Order order = new Order(1, "userTest", DateTime.Now, null, null, newOrderStatus, null, null);

            presenter.OnEditOrder(order);

            Assert.IsTrue(_controller.UpdateOrderStatusCalled);
            Assert.IsTrue(_controller.GetOrdersCalled);
            Assert.IsTrue(_view.ShowOrdersCalled);
            Assert.AreEqual(2, _view.TotalOrdersCount);
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion
    }
    
    namespace Mocks
    {
        class MockDefaultView : IDefaultView
        {
            public bool ShowOrdersCalled = false;
            public bool TotalOrdersCountCalled = false;
            public bool ShowUsersCalled = false;
            public bool TotalUsersCountCalled = false;

            private int _totalOrders = 2;
            private int _totalUsers = 5;

            #region IDefaultView Members

            public void ShowOrders(ICollection<Order> orders)
            {
                ShowOrdersCalled = true;
            }

            public int TotalOrdersCount
            {
                get
                {
                    return _totalOrders;
                }
                set
                {
                    _totalOrders = value;
                    TotalOrdersCountCalled = true;
                }
            }

            public void ShowUsers(MembershipUserCollection users)
            {
                ShowUsersCalled = true;
            }

            public int TotalUsersCount
            {
                get
                {
                    return _totalUsers;
                }
                set
                {
                    _totalUsers = value;
                    TotalUsersCountCalled = true;
                }
            }

            #endregion
        }
    }
}
